﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using EZSockets;

namespace SimCNC
{
    public partial class ToolOffset : Form
    {
        EZSockets.MitCom simTool = null;
        public ToolOffset(MitCom simToolOffset)
        {
            InitializeComponent();
            simTool = simToolOffset;
        }
        
        private void ToolOffset_Load(object sender, EventArgs e)
        {
           //获取刀具偏置组数
            int count;
            simTool.GetToolSetSize(out count);
            tbToolNum.Text = count.ToString();
        }
        /// <summary>
        /// 重绘
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GBTool_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.Clear(GBTool.BackColor);
            e.Graphics.DrawString(GBTool.Text, GBTool.Font, Brushes.Black, 10, 1);
            e.Graphics.DrawLine(Pens.Black, 1, 7, 8, 7);
            e.Graphics.DrawLine(Pens.Black, e.Graphics.MeasureString(GBTool.Text, GBTool.Font).Width + 8, 7, GBTool.Width - 2, 7);
            e.Graphics.DrawLine(Pens.Black, 1, 7, 1, GBTool.Height - 2);
            e.Graphics.DrawLine(Pens.Black, 1, GBTool.Height - 2, GBTool.Width - 2, GBTool.Height - 2);
            e.Graphics.DrawLine(Pens.Black, GBTool.Width - 2, 7, GBTool.Width - 2, GBTool.Height - 2);

        }


        void GetToolOffSetInfo()
        {
            int toolInfo = int.Parse(tbToolNum.Text);
            double loff;
            double lwear;
            double diameter;
            double dwear;
            int plNo;
            int plWear;
            int plDia;
            int plDWear;

            for (int i = 1; i <= toolInfo; i++)
            {
                simTool.GetToolOffSet(4, 0, i, out loff, out plNo);
                simTool.GetToolOffSet(4, 1, i, out lwear, out plWear);
                simTool.GetToolOffSet(4, 2, i, out diameter, out plDia);
                simTool.GetToolOffSet(4, 3, i, out dwear, out plDWear);
                if (dgvToolOffset.Rows.Count <= toolInfo)
                {
                    dgvToolOffset.Rows.Add(i, loff, lwear, diameter, dwear);
                }
                else
                {
                    DataGridViewRow dr = dgvToolOffset.Rows[i];
                    dr.Cells[1].Value = loff;
                    dr.Cells[2].Value = lwear;
                    dr.Cells[3].Value = diameter;
                    dr.Cells[4].Value = dwear;
                }

            }
        }

        /// <summary>
        /// 刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            GetToolOffSetInfo();
        }
       
    }
}
